#include <boost\bind.hpp>
#include <boost\asio.hpp>
#include <boost\thread\thread.hpp>
#include <boost\date_time\posix_time\posix_time.hpp>
#include <iostream>
using namespace std;
class printer
{
public:
	printer(boost::asio::io_service & io):
	  strand_(io),timer1(io,boost::posix_time::seconds(1)),timer2(io,boost::posix_time::seconds(1)),count(0){
		  timer1.async_wait(strand_.wrap(boost::bind(&printer::print1,this)));
		  timer2.async_wait(strand_.wrap(boost::bind(&printer::print2,this)));
	}
	~printer()
	{
		cout<<"final count is"<<count;
	}
	void print1()
	{
		if(count<10)
		{
				cout<<"timer1 count"<<count<<endl;
				++count;
				timer1.expires_at(timer1.expires_at()+boost::posix_time::seconds(1));
				timer1.async_wait(strand_.wrap(boost::bind(&printer::print1,this)));
		}
	}
	void print2()
	{	
		if(count<10)
		{
				cout<<"timer2 count"<<count<<endl;
				++count;
				timer2.expires_at(timer2.expires_at()+boost::posix_time::seconds(1));
				timer2.async_wait(strand_.wrap(boost::bind(&printer::print2,this)));
		}
		
	}
private:
	boost::asio::strand strand_;
	boost::asio::deadline_timer timer1;
	boost::asio::deadline_timer timer2;
	int count;
};
int main()
{
	boost::asio::io_service io;
	printer pt(io);
	boost::thread td(boost::bind(&boost::asio::io_service::run,&io));
	io.run();
	td.join();
	return 0;

}
